<!-- 列表 -->
<template>
	<view class="list">
		<view class="list-item" v-for="item in list" :key="item.id" @click="handleNavToDetailPage(item.id)">
			<view class="header">
				<text class="title">【{{item.category_name}}】{{item.name}}</text>
				<text class="price">{{parseFloat(item.budget) ? item.budget + '元': '面议'}}</text>
			</view>
			<view class="body">
				<text class="desc">{{item.remark || '　'}}</text>
			</view>
			<view class="footer">
				<text class="datetime">需求时间：{{item.create_time}}</text>
			</view>
		</view>
		
		<!-- 暂无数据 -->
		<c-empty-data v-if="!list.length && !loadingState.default"></c-empty-data>
		<!-- loading -->
		<view style="margin-top: 20rpx;">
			<c-loading :loadingState="loadingState"></c-loading>
		</view>
	</view>
</template>

<script setup>
	import { storeToRefs } from 'pinia';
	import { useMyNeedsStore } from "../store.js";
	
	const { list, loadingState } = storeToRefs(useMyNeedsStore());
	
	// 跳转到详情页
	const handleNavToDetailPage = (id) => {
		uni.navigateTo({
			url: '/pagesC-my/need-detail/index?id=' + id
		});
	}
</script>

<style lang="scss" scoped>
	.list {
		padding: 32rpx 25rpx;

		&-item {
			height: 200rpx;
			padding: 24rpx 20rpx 0 36rpx;
			background: #FFFFFF;
			border-radius: 20rpx;
			box-sizing: border-box;

			&:active {
				background-color: #f8f8f8;
			}

			&+.list-item {
				margin-top: 25rpx;
			}

			.header {
				display: flex;
				align-items: center;

				.title {
					flex-grow: 1;
					width: 0;
					font-weight: bold;
					font-size: 30rpx;
					color: #222222;
					line-height: 1.5;
					padding-right: 20rpx;
					margin-left: -12rpx;
					text-overflow: ellipsis;
					overflow: hidden;
					white-space: nowrap;
				}
				
				.price {
					flex-shrink: 0;
					font-weight: bold;
					font-size: 30rpx;
					color: #FE3333;
					line-height: 1.5;
				}
			}

			.body {
				display: flex;
				align-items: center;
				margin-top: 20rpx;

				.desc {
					display: block;
					font-size: 28rpx;
					color: #999999;
					text-overflow: ellipsis;
					overflow: hidden;
					white-space: nowrap;
				}
			}

			.footer {
				display: flex;
				align-items: center;
				margin-top: 14rpx;

				.datetime {
					font-size: 28rpx;
					color: #999999;
				}
			}
		}
	}
</style>